//
//  UIViewController+Extexsion.swift
//  AispeechMobileApp
//
//  Created by 孙鹏 on 2019/2/28.
//  Copyright © 2019 Lee. All rights reserved.
//

import UIKit

extension UIViewController {
    
    //获取控制器
    func getCurrentVC() -> UIViewController {
        let rootViewController = UIApplication.shared.keyWindow?.rootViewController
        return sdc_topViewControllerForViewController(rootViewController: rootViewController ?? UIViewController())
    }
    
    func sdc_topViewControllerForViewController(rootViewController:UIViewController) -> UIViewController {
    
        if rootViewController.isKind(of: UINavigationController.self) {
            let nav = rootViewController as! UINavigationController
            return sdc_topViewControllerForViewController(rootViewController:nav.visibleViewController ?? UINavigationController())
        }
        if rootViewController.presentedViewController != nil {
            return sdc_topViewControllerForViewController(rootViewController:rootViewController.presentedViewController ?? UIViewController())
        }
        
        return rootViewController
        
    }
    
}
